using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.ComponentModel.Design;
using System.Collections.Generic;
using Widgetsphere.Generator.Models;

namespace Widgetsphere.Generator.Design.Converters
{
	internal class UnitTestDependencyConverter : TypeConverter
	{
		public UnitTestDependencyConverter()
		{
		}

		public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
		{
			if (destinationType == typeof(string)) return true;
			return base.CanConvertTo(context, destinationType);
		}

		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
		{
			try
			{
				if (destinationType == typeof(string))
				{
					int count = ((List<Table>)value).Count;
					return count + " item" + (count == 1 ? "" : "s");
				}
			}
			catch (Exception ex) { }
			return null;
		}

	}
}
